package com.beadhouse.retreat.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.beadhouse.common.dto.JSONResponse;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.RetreatEntity;
import com.beadhouse.retreat.ao.DealRetreatAo;
import com.beadhouse.retreat.ao.UpdateRetreatAo;
import com.beadhouse.retreat.dto.RetreatDto;
import com.beadhouse.retreat.support.service.RetreatServiceImpl;


import com.github.pagehelper.PageInfo;




@RestController
@RequestMapping("/api/retreat")
public class RetreatCountroller {
	@Autowired
	RetreatServiceImpl rsi;
	
	@PostMapping("/add")
	@ResponseBody
	public JSONResponse dealRetreat(DealRetreatAo ao) {
		try {
			rsi.addRetreatRecord(ao);
		}catch(BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return JSONResponse.ok();
		
	}
	@GetMapping("/list")
	@ResponseBody
	public JSONResponse quryRetreat(String pageNum,String key){		
		PageInfo<RetreatEntity> dto;
		try {
			dto = rsi.listretreatRecord(pageNum,key);
			return JSONResponse.ok(dto);
		}catch(BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	@GetMapping("/delete")
	@ResponseBody
	public JSONResponse delRetreat(String id) {
		try {
			rsi.deleteRetreatRecord(id);
		}catch(BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return JSONResponse.ok();
	}
	@PostMapping("/update")
	@ResponseBody
	public JSONResponse updRetreat(UpdateRetreatAo ao) {
		
		

		try {
			rsi.updateRetreatRecord(ao);
		}catch(BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return JSONResponse.ok();
	}
	
}
